/*
 * TITLE:RequestToServerTable
 * AUTHOR:Manori Thakur
 * PURPOSE: Parent class for all requests to game server
 */
package clientrequest;

import android.util.Log;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Vector;

import clientcore.ConnectServer;

public class RequestToServer {
	private static final String TAG = RequestToServer.class.getSimpleName();
    protected short size = 0;
    protected DataOutputStream outToServer = null;


    public RequestToServer() {

    }

    public void send(short requestCode, Vector args) {

    }

    public void setOut(DataOutputStream sendServer) {
        this.outToServer = sendServer;        
    }

    /**
     * Reverses the bytes to send the data in little endian for to game server
     * @param val
     */
    protected void writeShort(short val) {
    	try { 
        	outToServer.writeShort(Short.reverseBytes(val));
            outToServer.flush();
        } catch (IOException ex) {
            Log.e(TAG,"IO Exception in method writeShort()"+ex.toString());
        }
    }

    protected void writeInt(int val) {
        try {
            outToServer.writeInt(Integer.reverseBytes(val));
            outToServer.flush();
        } catch (IOException ex) {
        	Log.e(TAG,"IO Exception in method writeInt()"+ex.toString());
        }
    }
    
    /**
     * Sends the length of the string in reversed order and then the actual string
     * @param val
     */
    protected void writeString(String val) {
    	try {
            writeShort((short)val.length());            
            outToServer.writeBytes(val);
            outToServer.flush();
        } catch (IOException ex) {
        	Log.e(TAG,"IO Exception in method writeString()"+ex.toString());
        }
    }

}


